Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updated structs #237

Merged
merged 1 commit into from
Jul 16, 2024
Merged

chore: updated structs #237

merged 1 commit into from
Jul 16, 2024

Conversation

Mikelle
Copy link
Member

@Mikelle Mikelle commented Jul 15, 2024

Updated solidity structs, so they will take less storage.

Before (original struct):

struct PreConfCommitment {
    bool isUsed;                     // 1 byte
    address bidder;                  // 20 bytes
    address commiter;                // 20 bytes
    uint256 bid;                     // 32 bytes
    uint64 blockNumber;              // 8 bytes
    bytes32 bidHash;                 // 32 bytes
    uint64 decayStartTimeStamp;      // 8 bytes
    uint64 decayEndTimeStamp;        // 8 bytes
    string txnHash;                  // dynamic
    string revertingTxHashes;        // dynamic
    bytes32 commitmentHash;          // 32 bytes
    bytes bidSignature;              // dynamic
    bytes commitmentSignature;       // dynamic
    uint64 dispatchTimestamp;        // 8 bytes
    bytes sharedSecretKey;           // dynamic
}
  1. Slot 1: bool isUsed (1 byte) + address bidder (20 bytes) + padding (11 bytes).
  2. Slot 2: address commiter (20 bytes) + padding (12 bytes).
  3. Slot 3: uint256 bid (32 bytes).
  4. Slot 4: uint64 blockNumber (8 bytes) + padding (24 bytes).
  5. Slot 5: bytes32 bidHash (32 bytes).
  6. Slot 6: uint64 decayStartTimeStamp (8 bytes) + uint64 decayEndTimeStamp (8 bytes) + padding (16 bytes).
  7. Slot 7: uint64 dispatchTimestamp (8 bytes) + padding (24 bytes).
  8. Slot 8: bytes32 commitmentHash (32 bytes).

Dynamic types (string txnHash, string revertingTxHashes, bytes bidSignature, bytes commitmentSignature, bytes sharedSecretKey) are stored in separate slots because they are dynamic arrays. Each dynamic type will occupy a new slot, pointing to its data location. There are 5 of them

Total slots: 8 + 5 = 13

Optimized struct:

struct PreConfCommitment {
    address bidder;                  // 20 bytes
    bool isUsed;                     // 1 byte
    uint64 blockNumber;              // 8 bytes
    uint64 decayStartTimeStamp;      // 8 bytes
    uint64 decayEndTimeStamp;        // 8 bytes
    uint64 dispatchTimestamp;        // 8 bytes
    address commiter;                // 20 bytes
    uint256 bid;                     // 32 bytes
    bytes32 bidHash;                 // 32 bytes
    bytes32 commitmentHash;          // 32 bytes
    bytes bidSignature;              // dynamic
    bytes commitmentSignature;       // dynamic
    bytes sharedSecretKey;           // dynamic
    string txnHash;                  // dynamic
    string revertingTxHashes;        // dynamic
}
  1. Slot 1: address bidder (20 bytes) + bool isUsed (1 byte) + padding (11 bytes).
  2. Slot 2: address commiter (20 bytes) + padding (12 bytes).
  3. Slot 3: uint256 bid (32 bytes).
  4. Slot 4: bytes32 bidHash (32 bytes).
  5. Slot 5: bytes32 commitmentHash (32 bytes).
  6. Slot 6: uint64 blockNumber (8 bytes) + uint64 decayStartTimeStamp (8 bytes) + uint64 decayEndTimeStamp (8 bytes) + uint64 dispatchTimestamp (8 bytes).

Total slots: 6 + 5 = 11

@Mikelle Mikelle requested review from ckartik and shaspitz July 15, 2024 23:42
@Mikelle Mikelle self-assigned this Jul 15, 2024
@Mikelle Mikelle merged commit bdd0d5f into main Jul 16, 2024
5 of 6 checks passed
@Mikelle Mikelle deleted the fix/236/struct-order-solidity branch July 16, 2024 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants